package com.waves.design.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 容器构件类
 */
public class FolderFile extends AbstractFile {

    private List<AbstractFile> list = new ArrayList();
    private String name;

    public FolderFile(String name) {
        this.name = name;
    }

    @Override
    public void add(AbstractFile file) {
        list.add(file);
    }

    @Override
    public void remove(AbstractFile file) {
        list.remove(file);
    }

    @Override
    public AbstractFile getChild(int i) {

        return list.get(i);
    }

    @Override
    public void killVirus() {
        System.out.println("对文件夹" + name + "进行杀毒");
        for (AbstractFile file : list) {
            file.killVirus();
        }

    }
}
